// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

namespace SnapObjects.Data
{
    internal class JoinElement : TableElement
    {
        public JoinElement(string schema, string table, string alias, SqlJoinType joinType)
            : base(schema, table, alias)
        {
            this.JoinType = joinType;
        }

        public JoinElement(string clause, string name, SqlJoinType joinType) : base(clause, name)
        {
            this.JoinType = joinType;
        }

        public JoinElement(SqlBuildStatement statement, string alias, SqlJoinType joinType)
            : base(statement, alias)
        {
            this.JoinType = joinType;
        }

        public override SqlElementType ElementType => SqlElementType.Join;

        public SqlJoinType JoinType { get; }

        public ConditionElement On { get; set; }

        public override SqlElement Clone()
        {
            return new JoinElement(this.Table, this.ElementName, this.JoinType)
            {
                On = (ConditionElement)this.On.Clone(),
                Alias = this.Alias,
                Table = this.Table,
                Schema = this.Schema,
                TableType = this.TableType,
                Statement = this.Statement?.Clone()
            };
        }
    }
}
